
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_DATO_NOTAT_EBAS_STUDERENDE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_DATO_NOTAT] DROP CONSTRAINT FK_EBAS_DATO_NOTAT_EBAS_STUDERENDE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_FAKTURA_DETALJE_EBAS_STUDERENDE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_FAKTURA_DETALJE] DROP CONSTRAINT FK_EBAS_FAKTURA_DETALJE_EBAS_STUDERENDE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_GRUPPE_STUDERENDE_EBAS_STUDERENDE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_GRUPPE_STUDERENDE] DROP CONSTRAINT FK_EBAS_GRUPPE_STUDERENDE_EBAS_STUDERENDE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_STUDERENDE_FAG_EBAS_STUDERENDE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_STUDERENDE_FAG] DROP CONSTRAINT FK_EBAS_STUDERENDE_FAG_EBAS_STUDERENDE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_STUDERENDE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EBAS_STUDERENDE]
GO

CREATE TABLE [dbo].[EBAS_STUDERENDE] (
	[GUID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[INIT] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[CPR_NR] [varchar] (50) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[FORNAVN] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[EFTERNAVN] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[TITEL] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NULL ,
	[SKOLE_ID] [varchar] (50) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[SKOLE_DATO] [datetime] NOT NULL ,
	[OK_DATO] [datetime] NOT NULL ,
	[BEMAERKNING] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NULL ,
	[UDDANNELSE] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NULL ,
	[STATUS_GUID] [uniqueidentifier] NOT NULL ,
	[IDENTIFIKATION_GUID] [uniqueidentifier] NOT NULL ,
	[SIKKERHED_BRUGER_GUID] [uniqueidentifier] NULL ,
	[SLETTET] [bit] NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_STUDERENDE] WITH NOCHECK ADD 
	CONSTRAINT [DF_EBAS_STUDERENDE_SLETTET] DEFAULT (0) FOR [SLETTET],
	CONSTRAINT [DF_EBAS_STUDERENDE_INIT] DEFAULT ('') FOR [INIT],	
	CONSTRAINT [PK_STUDERENDE] PRIMARY KEY  CLUSTERED 
	(
		[GUID]
	)  ON [PRIMARY] 
GO

 CREATE  UNIQUE  INDEX [IDX_STUDERENDE_CPR_NR] ON [dbo].[EBAS_STUDERENDE]([CPR_NR]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_STUDERENDE] ADD 
	CONSTRAINT [FK_EBAS_STUDERENDE_EBAS_IDENTIFIKATION] FOREIGN KEY 
	(
		[IDENTIFIKATION_GUID]
	) REFERENCES [dbo].[EBAS_IDENTIFIKATION] (
		[GUID]
	),
	CONSTRAINT [FK_EBAS_STUDERENDE_EBAS_SIKKERHED_BRUGER] FOREIGN KEY 
	(
		[SIKKERHED_BRUGER_GUID]
	) REFERENCES [dbo].[EBAS_SIKKERHED_BRUGER] (
		[GUID]
	),
	CONSTRAINT [FK_EBAS_STUDERENDE_EBAS_STATUS] FOREIGN KEY 
	(
		[STATUS_GUID]
	) REFERENCES [dbo].[EBAS_STATUS] (
		[GUID]
	)
GO
